package com.gupao.rpc.protocol.serializer;

import com.gupao.rpc.protocol.constants.SerialType;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 序列化管理器
 *
 * @author SuperWein
 */
public class RpcSerializerManager {

    private static final Map<Byte, IRpcSerializer> serializerMap = new ConcurrentHashMap<>();

    static {
        serializerMap.put(SerialType.JSON.value(), new JsonRpcSerializer());
        serializerMap.put(SerialType.JSON.value(), new JavaRpcSerializer());
    }

    /**
     * 获取序列化器
     *
     * @param serialType 序列化列席
     * @return 序列化器
     */
    public static IRpcSerializer getSerializer(byte serialType) {
        IRpcSerializer serializer = serializerMap.get(serialType);
        if (serializer == null) {
            serializer = new JsonRpcSerializer();
        }
        return serializer;
    }

}
